package cn.com.duiba.millionaire.center.biz.dao.impl;

import cn.com.duiba.millionaire.center.biz.constants.DatabaseSchema;
import cn.com.duiba.millionaire.center.biz.dao.BaseDao;
import cn.com.duiba.millionaire.center.biz.dao.MillionaireQuestionDao;
import cn.com.duiba.millionaire.center.biz.entity.MillionaireQuestionEntity;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by sty on 1/18/18.
 */
@Repository
public class MillionaireQuestionDaoImpl extends BaseDao implements MillionaireQuestionDao {
    @Override
    public MillionaireQuestionEntity insert(MillionaireQuestionEntity millionaireQuestionEntity) {
        insert("insert" , millionaireQuestionEntity);
        return millionaireQuestionEntity;
    }

    @Override
    public int updateById(MillionaireQuestionEntity millionaireQuestionEntity) {
        return update("updateById", millionaireQuestionEntity);
    }

    @Override
    public MillionaireQuestionEntity findById(Long id) {
        return selectOne("selectById", id);
    }

    @Override
    public List<MillionaireQuestionEntity> findByIds(List<Long> ids) {
        if(CollectionUtils.isEmpty(ids)){
            return Lists.newArrayList();
        }
        Map<String, Object> params = Maps.newHashMap();
        params.put("ids", ids);
        return selectList("selectByIds", params);
    }

    @Override
    public int deleteById(Long id) {
        return update("deleteById", id);
    }


    @Override
    public List<MillionaireQuestionEntity> findByBagId(Long questionBagId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("questionBagId", questionBagId);
        return selectList("selectByBagId", params);
    }

    @Override
    protected DatabaseSchema chooseSchema() {
        return DatabaseSchema.MILLIONAIRE_CONFIG;
    }
}
